home *** CD-ROM | disk | FTP | other *** search
- ;void write_portion(strg,start,num_ch,col,row,color);
- ; unsigned char *strg,start,num_ch,col,row,color;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _snow_protect:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _write_portion
- _write_portion proc near
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- pushf ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov cl,_snow_protect ;get _snow_protect
- push ds ;save Turbo's DS
- mov ax,_video_buffer ;fetch Videobuffer
- mov es,ax ;ES pts to buffer
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: sub bx,bx ;
- mov bl,[bp+12] ;Row
- dec bx ;count from zero
- mov [bp+12],cl ;save _snow_protect
- sub cx,cx ;
- mov cl,[bp+10] ;Col
- dec cx ;count from zero
- mov ax,160 ;bytes per row
- mul bl ;row offset
- shl cx,1 ;dble cols for attributes
- add ax,cx ;offset to start position
- mov di,ax ;ES:DI pts to start
- push si ;must find string length
- sub cx,cx ;count in CX
- L000: inc si ;forward strg ptr
- inc cx ;inc counter
- cmp byte ptr[si],0 ;end of string?
- jne L000 ;loop if not
- pop si ;SI back to start of string
- dec si ;adjust for start of loop below
- mov bh,1 ;error code 1 = null strg
- jcxz L7 ;quit if null
- mov al,[bp+6] ;startpoint
- inc al ;count from 1
- inc bh ;2 = Start outside of string
- cmp al,cl ;start point in range?
- jnbe L7 ;quit if not
- inc bh ;3 = not enough room for NumCh
- cmp byte ptr[bp+8],0 ;check for NumCh nonzero
- jz L7 ;quit if zero
- mov ah,al ;copy startpoint
- add ah,[bp+8] ;add number chars
- dec ah ;adjust
- cmp ah,cl ;in range?
- jna L1 ;jump ahead if OK
- sub cl,[bp+6] ;number chars to write
- inc cl ;adjust
- jmp short L2 ;
- L1: mov cl,[bp+8] ;num chars to write
- sub bh,bh ;0 = no error
- L2: sub ah,ah ;extend byte value
- add si,ax ;offset string ptr
- cld ;forward direction
- mov ah,[bp+14] ;get screen attribute
- L3: lodsb ;get a char from Strg
- cmp byte ptr[bp+12],0 ;protect against snow?
- je L6 ;jump if not
- push ax ;save char-attri
- mov dx,3dah ;status byte address
- L4: in al,dx ;get status byte
- test al,1 ;test bit
- jnz L4 ;loop till 0
- cli ;disable interrupts
- L5: in al,dx ;get status byte
- test al,1 ;test bit
- jz L5 ;loop till 1, then write
- pop ax ;restore char-attri
- L6: stosw ;write the char and color
- loop L3 ;loop till finished
- L7: sti ;reenable interrupts
- pop ds ;restore DS and quit
- mov _error_code,bh ;set _error_code
- popf ;
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _write_portion endp
- _TEXT ENDS
- END